package com.company.project.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.company.project.common.utils.Func;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import java.util.List;
import com.company.project.common.utils.DataResult;

import com.company.project.entity.TLoginLogEntity;
import com.company.project.service.TLoginLogService;



/**
 * 
 *
 * @author wenbin
 * @email *****@mail.com
 * @date 2023-11-29 17:51:48
 */
@Controller
@RequestMapping("/")
public class TLoginLogController {
    @Autowired
    private TLoginLogService tLoginLogService;


    /**
    * 跳转到页面
    */
    @GetMapping("/index/tLoginLog")
    public String tLoginLog() {
        return "tloginlog/list";
        }

    @ApiOperation(value = "新增")
    @PostMapping("tLoginLog/add")
    @RequiresPermissions("tLoginLog:add")
    @ResponseBody
    public DataResult add(@RequestBody TLoginLogEntity tLoginLog){
        tLoginLogService.save(tLoginLog);
        return DataResult.success();
    }

    @ApiOperation(value = "删除")
    @DeleteMapping("tLoginLog/delete")
    @RequiresPermissions("tLoginLog:delete")
    @ResponseBody
    public DataResult delete(@RequestBody @ApiParam(value = "id集合") List<String> ids){
        tLoginLogService.removeByIds(ids);
        return DataResult.success();
    }

    @ApiOperation(value = "更新")
    @PutMapping("tLoginLog/update")
    @RequiresPermissions("tLoginLog:update")
    @ResponseBody
    public DataResult update(@RequestBody TLoginLogEntity tLoginLog){
        tLoginLogService.updateById(tLoginLog);
        return DataResult.success();
    }

    @ApiOperation(value = "查询分页数据")
    @PostMapping("tLoginLog/listByPage")
    @RequiresPermissions("tLoginLog:list")
    @ResponseBody
    public DataResult findListByPage(@RequestBody TLoginLogEntity tLoginLog){
        Page page = new Page(tLoginLog.getPage(), tLoginLog.getLimit());
        LambdaQueryWrapper<TLoginLogEntity> queryWrapper = Wrappers.lambdaQuery();
        if (Func.isNotEmpty(tLoginLog.getUserid()))  queryWrapper.like(TLoginLogEntity::getUserid,tLoginLog.getUserid());
        queryWrapper.orderByDesc(TLoginLogEntity::getLogintime);
        //查询条件示例
        //queryWrapper.eq(TLoginLogEntity::getId, tLoginLog.getId());
        IPage<TLoginLogEntity> iPage = tLoginLogService.findListByPage(page, tLoginLog);
        return DataResult.success(iPage);
    }

}
